home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Rechen2a.cpp < prev    next >
C/C++ Source or Header  |  1998-12-27  |  2KB  |  60 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Rechen2a.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. TForm1 *Form1;
  10. double Zahl1, Zahl2, Ergebnis;
  11.  
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14.     : TForm(Owner)
  15. {
  16. }
  17. //---------------------------------------------------------------------------
  18. void __fastcall TForm1::Label3Click(TObject *Sender)
  19. {
  20.   randomize ();
  21.   Zahl1 = double (random (1000)) /10;
  22.   Zahl2 = 0; //double (random (1000)) /10;
  23.   Label1->Caption = String (Zahl1);
  24.   Label2->Caption = String (Zahl2);
  25.   Label3->Caption = "WΣhle die Rechenart!";
  26. }
  27. //---------------------------------------------------------------------------
  28.  
  29. void __fastcall TForm1::Button1Click(TObject *Sender)
  30. {
  31.   Ergebnis = Zahl1 + Zahl2;
  32.   Label3->Caption = "Ergebnis der Addition: " + String(Ergebnis);
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::Button2Click(TObject *Sender)
  36. {
  37.   Ergebnis = Zahl1 - Zahl2;
  38.   Label3->Caption = "Ergebnis der Subtraktion: " + String(Ergebnis);
  39. }
  40. //---------------------------------------------------------------------------
  41. void __fastcall TForm1::Button3Click(TObject *Sender)
  42. {
  43.   Ergebnis = Zahl1 * Zahl2;
  44.   Label3->Caption = "Ergebnis der Multiplikation: " + String(Ergebnis);
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::Button4Click(TObject *Sender)
  48. {
  49.   if (Zahl2!=0)
  50.   {
  51.     Ergebnis = Zahl1 / Zahl2;
  52.     Label3->Caption = "Ergebnis der Division: " + String(Ergebnis);
  53.   }
  54.   else
  55.   {
  56.     Label3->Caption = "Division durch Null!";
  57.   }
  58. }
  59. //---------------------------------------------------------------------------
  60.